"""
5、完成普通文件文件的seek，二进制文件的seek（代码编写与上课一致即可）
"""
#seek, seek_set，相对于开头偏移, seek_cur相对于当前位置偏移,seek_end相对于文件末尾偏移
import os

def seek_start():
    file = open('file1','r+',encoding='utf-8')
    file.seek(3,os.SEEK_SET)
    txt = file.read(5)
    print(txt)
    file.close()

def seek_end():
    file = open('file1','r+',encoding='utf-8')
    file.seek(0,os.SEEK_END)
    file.close()

def seek_cur():
    file = open('file1','r+',encoding='utf-8')
    file.seek(0,os.SEEK_CUR)
    txt=file.read(6)
    print(txt)
    file.close()

def seek_b():
    file = open('file1','rb+')
    # file.seek(-3,os.SEEK_END)
    file.seek(3,os.SEEK_SET)
    file.seek(4,os.SEEK_CUR)

    by=file.read(6)
    print(by)
    file.close()

def seek_copy():
    file1 = open('deskjt.png','rb+')
    file2 = open('deskjt_copy.png','wb')
    d_copy =file1.read()
    file2.write(d_copy)
    file1.close()
    file2.close()


if __name__ == '__main__':
    # seek_start()
    # seek_cur()
    # seek_b()
    seek_copy()